package camera.OpenGl.utils;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.ShortBuffer;

/**
 * Created by Administrator on 2017/12/20.
 */

public class ByteBufferUtils {
    /**
     * 创建float类型的byteBuffer
     * @return
     */
    public static FloatBuffer makeFloteByteBuffer(float[] vertexs){
        FloatBuffer floatBuffer=null;
        ByteBuffer byteBuffer = ByteBuffer.allocateDirect(vertexs.length * 4);
        byteBuffer.order(ByteOrder.nativeOrder());
        floatBuffer=byteBuffer.asFloatBuffer();
        floatBuffer.put(vertexs);
        floatBuffer.position(0);
        return floatBuffer;
    }
    /**
     * 创建short类型的byteBuffer
     * @return
     */
    public static ShortBuffer makeShortBuffer(short[] vertexs){
        ShortBuffer floatBuffer=null;
        ByteBuffer byteBuffer = ByteBuffer.allocateDirect(vertexs.length * 4);
        byteBuffer.order(ByteOrder.nativeOrder());
        floatBuffer=byteBuffer.asShortBuffer();
        floatBuffer.put(vertexs);
        floatBuffer.position(0);
        return floatBuffer;
    }
}
